
package com.bysj.service.impl;

import java.util.ArrayList;

import com.bysj.dao.AdvDao;
import com.bysj.dao.impl.AdvDaoImpl;
import com.bysj.entity.Adv;
import com.bysj.service.AdvService;

public class AdvServiceImpl implements AdvService{
	private AdvDao ad=new AdvDaoImpl();
	@Override
	public void addAdv(Adv adv) {
		String sql="insert into adv(title,time,type,content) values(?,?,?,?)";
		ad.addAdv(sql, adv);
	}

	@Override
	public void delAdv(Adv adv) {
		String sql="delete from adv where id=?";
		ad.delAdv(sql, adv);
	}

	@Override
	public void updateAdv(Adv adv) {

	}

	@Override
	public ArrayList<Adv> queryAllAdv() {
		String sql="select id,title,type,time,content,docname from adv";
		return ad.queryAllAdv(sql);
	}

	@Override
	public int countAllAdv() {
		String sql="select COUNT(*) from adv";
		return ad.countAllAdv(sql);
	}

	@Override
	public Adv queryAdv(Adv adv) {
		String sql="select id,title,type,time,content,docname from adv where id= ?";
		return ad.queryAdv(sql,adv);
	}

	@Override
	public ArrayList<Adv> FenyeQueryAdv(int page, int rows) {
		String sql="select id,title,type,time,content,docname from adv limit ?,?";
		return ad.FenyeQueryAdv(sql, page, rows);
	}

	@Override
	public ArrayList<Adv> queryadvByType(Adv adv) {
		String sql="select id,title,type,time from adv where type= ? limit 1,5";
		return ad.queryadvBytype(sql,adv);
	}

	@Override
	public void updateAdvDocById(Adv adv) {
		String sql="update adv set docname=? where id=?";
		ad.updateAdvDocById(sql,adv);
	}

	@Override
	public ArrayList<Adv> FenyeQueryBytitle(int page,int rows,Adv adv) {
		String sql="select id,title,type,time,content,docname from adv where title like '%"+adv.getTitle()+"%' limit ?,?";
		return ad.FenyeQueryAdv(sql, page, rows);
	}

	@Override
	public ArrayList<Adv> FenyeQueryByContent(int page,int rows,Adv adv) {
		String sql="select id,title,type,time,content,docname from adv where  content like '%"+adv.getContent()+"%' limit ?,?";
		return ad.FenyeQueryAdv(sql, page, rows);
	}

	@Override
	public ArrayList<Adv> FenyeQueryByTime(int page,int rows,Adv adv) {
		String sql="select id,title,type,time,content,docname from adv where time like '%"+adv.getTime()+"%' limit ?,?";
		return ad.FenyeQueryAdv(sql, page, rows);
	}

	@Override
	public int countAllAdvbyTitle(Adv adv) {
		String sql="select COUNT(*) from adv where title like '%"+adv.getTitle()+"%'";
		return ad.countAllAdv(sql);
	}
	@Override
	public int countAllAdvbyContent(Adv adv) {
		String sql="select COUNT(*) from adv where content like '%"+adv.getContent()+"%'";
		return ad.countAllAdv(sql);
	}
	@Override
	public int countAllAdvbyTime(Adv adv) {
		String sql="select COUNT(*) from adv where time like '%"+adv.getTime()+"%'";
		return ad.countAllAdv(sql);
	}

	@Override
	public ArrayList<Adv> FenyeQueryByType(int nowPage, int pageRowNum, Adv adv) {
		String sql="select id,title,type,time,content,docname from adv where type like '%"+adv.getType()+"%' limit ?,?";
		return ad.FenyeQueryAdv(sql, nowPage, pageRowNum);
	}

	@Override
	public ArrayList<Adv> FenyeQueryById(int nowPage, int pageRowNum, Adv adv) {
		String sql="select id,title,type,time,content,docname from adv where id like '%"+adv.getId()+"%' limit ?,?";
		return ad.FenyeQueryAdv(sql, nowPage, pageRowNum);
	}

	@Override
	public int CountAdvById(Adv adv) {
		String sql="select COUNT(*) from adv where id like '%"+adv.getId()+"%'";
		return ad.countAllAdv(sql);
	}

	@Override
	public int CountAdvByType(Adv adv) {
		String sql="select COUNT(*) from adv where type like '%"+adv.getType()+"%'";
		return ad.countAllAdv(sql);
	}

}
